<?php 
header('Access-Control-Allow-Origin:*');  //支持全域名访问，不安全，部署后需要固定限制为客户端网址
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); //支持的http 动作
header('Access-Control-Allow-Headers:x-requested-with,content-type');  //响应头 请按照自己需求添加。
$conn = mysqli_connect("localhost","root","","fruit");
$conn->query("set names utf8");
// $keyword=$_GET["keyword"];
$type = $_GET["type"];
switch ($type) {
	case "con":
		$sql = "SELECT * FROM search ORDER BY `search`.`time` DESC";
		$ret = $conn->query($sql);
		$arr = array();
		while ($row = $ret->fetch_assoc()) {
			$arr[] = $row;
		}
		$str = json_encode($arr);
		echo '{"data":'.$str.'}';
	break;
	case "banner":
		$txt=$_GET["banner"];
		$sql =  "SELECT * FROM search WHERE sort like '%{$txt}%' ORDER BY `search`.`time` DESC";
		$ret = $conn->query($sql);
		$arr = array();
		while ($row = $ret->fetch_assoc()) {
			$arr[] = $row;
		}
		$str = json_encode($arr);
		echo '{"data":'.$str.'}';
	break;
}


 ?>